Info
First we need a csv or excel table with metadata that is also reflected in the filename parts. The metadata table has the name of the picture files. Here we add some HTML formatting to the cells containing the filename (e.g,. so that they expand when hovering the mouse). The parameter escape = FALSE is required in data table (r package to render the table) to render the images.
Code
library(DT)
library(dplyr)
library(here )
#-------------------------------------------------
# Read filenames from directory
metadata <- read.csv(file.path(here::here(),'Metadata_filenames.csv'))
folderWithPics <- paste0('Spring_jpg',.Platform$file.sep)
# add html component to column with file names
metadata$pic <- paste0('<img src=\'', folderWithPics, metadata$file, '\' height=\'70\' witdth = \'70\'></img>')
#metadata %>% relocate(file, .after = last_col())For this early test the following scheme was inferred from the filenames of files starting with “JP*“. Metadata table was created accordingly. Future versions should specify the remaining files or create a separate table for the other type of files available
Scheme
<specID>_<status>_<scanID><(desc)>_<rec>
Labels
specID: str + num specimen ID (JP01)
status: str specimen status (dead | invivo)
scanID: num + str scan number (1scan or scan1)
desc: OPTIONAL str + num additional description of number of scans, anatomy, state,version,etc
seq: num sequence number (053)
rec: str + num recording identifier (rec00182)
Legend:
<field> required field
<(field)> Optional field
Picture viewer
Here you can filter each column in the table filter boxes or click 'FILTER ROWS' button to see panes with filters.The filter panes display as well how many cells are there (but panes are not updated when filters are active)
Code
# Dynamic table -------------------------------------------------
datatable(
metadata, filter = "top",
rownames=FALSE, width="100%",
class='compact cell-border hover', # See CSS classes https://datatables.net/manual/styling/classes
extensions=c('Buttons','Select','SearchPanes'),
#selection = 'none',
selection = 1,
escape = FALSE,
options = list(
dom = 'Btip',
buttons=c('searchPanes','copy','csv','excel','pdf'),
language = list(searchPanes = list(collapse = "FILTER ROWS")),
columnDefs = list(
list(searchPanes = list(show = FALSE), targets = 5) #'target' will change how many panes
)
)
) Filter boxes in table and also filter panes above
Code
# Dynamic table -------------------------------------------------
datatable(
metadata, filter = "top",
rownames=FALSE, width="100%",
class='compact cell-border hover', # CSS classes https://datatables.net/manual/styling/classes
extensions=c('Buttons','Select','SearchPanes'),
#selection = 'none',
selection = 1,
escape = FALSE,
options = list(dom = 'PBfrtip', buttons=c('copy','csv','excel','pdf'),
columnDefs = list(list(
searchPanes = list(show = TRUE),
targets = 5
))),
)Just the table with filter boxes
Code
# Dynamic table -------------------------------------------------
library(DT)
library(dplyr)
# Render table (ref https://www.rdocumentation.org/packages/DT/versions/0.28/topics/datatable)
metadata %>%
datatable(
filter = "top",
rownames=FALSE, width="100%",
class='compact cell-border hover', # CSS classes https://datatables.net/manual/styling/classes
extensions=c('Buttons','Select','SearchPanes'),
selection = 'none',
options=list(dom='Bfrtip', buttons=c('copy','csv','excel','pdf')),
escape=FALSE
) %>%
DT::formatStyle(columns = colnames('file'), fontSize = '10%')